import Vue from 'vue'
import VueRouter from 'vue-router'
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    component: () => import('../views/index.vue'),
    meta: {active: 0}
  },
  {
    path: '/my',
    component: () => import('../views/my.vue'),
    meta: {active: 1}
  },
  {
    path: '/auction',
    component: () => import('../views/auction.vue'),
    meta: {active: 2}
  },
  {
    path: '/service',
    component: () => import('../views/service.vue'),
    meta: {active: 3}
  },
  {
    path: '/information',
    component: () => import('../views/information.vue'),
    meta: {active: 4}
  },
  {
    path: '/contact',
    component: () => import('../views/contact.vue'),
    meta: {active: 5}
  },
  {
    path: '/informationdetail',
    component: () => import('../views/informationdetail.vue'),
    meta: {active: 4}
  },
  {
    path: '/auctiondetail',
    component: () => import('../views/auctiondetail.vue'),
    meta: {active: 2}
  },
  {
    path: '/offer',
    component: () => import('../views/offer.vue'),
    meta: {active: 2}
  },
  {
    path: '/freehand',
    component: () => import('../views/freehand.vue'),
    meta: {active: 2}
  },
  {
    path: '/shoting',
    component: () => import('../views/shoting.vue'),
    meta: {active: 2}
  },
  {
    path: '/shopAuctions',
    component: () => import('../views/shopAuctions.vue'),
    meta: {active: 2}
  }
]

const router = new VueRouter({
  routes,
  mode:"history",
  scrollBehavior (to, from, savedPosition) {
    if (to.path!='/') {
     return { y: 0 }
    } else {
      return { y: sessionStorage.getItem('scrollTop') }
    }
  }
})

export default router
